using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Tool.BaseClass;
using Tool.Model;
using Tool.Utilty;

namespace Tool
{
	public class DataLog : UserControl
	{
		private System.ComponentModel.IContainer components = null;

		private DataGridView gv_list;

		private DataGridViewTextBoxColumn CategoryName;

		private DataGridViewTextBoxColumn LogMessage;

		private Button bt_export;

		private Button btnClear;

		private Label lb_msg;

		public DataLog()
		{
			this.InitializeComponent();
		}

		private void DataLog_Load(object sender, EventArgs e)
		{
			this.gv_list.AutoGenerateColumns = false;
			this.gv_list.BackgroundColor = System.Drawing.Color.White;
			this.gv_list.RowHeadersVisible = false;
			this.gv_list.AllowUserToAddRows = false;
			this.gv_list.AllowUserToDeleteRows = false;
			this.gv_list.MultiSelect = false;
			this.gv_list.ReadOnly = true;
			this.gv_list.SelectionMode = DataGridViewSelectionMode.CellSelect;
			List<GClass30> list = this.method_0();
			this.gv_list.DataSource = new System.ComponentModel.BindingList<GClass30>(list);
			this.lb_msg.Text = "共“" + list.Count.ToString() + "”项";
			this.lb_msg.ForeColor = System.Drawing.Color.Green;
		}

		private List<GClass30> method_0()
		{
			List<GClass30> list = GClass28.smethod_3();
			if (list.Count > 0)
			{
				for (int i = 0; i < list.Count; i++)
				{
					list[i].LogCategoryName = GClass37.smethod_2<GClass19.GClass21.GEnum0>(list[i].LogCategoryId);
				}
			}
			return list;
		}

		private void bt_export_Click(object sender, EventArgs e)
		{
			List<GClass30> list = this.method_0();
			if (list.Count <= 0)
			{
				this.lb_msg.Text = "数据为空,导出失败.";
				this.lb_msg.ForeColor = System.Drawing.Color.Red;
			}
			else
			{
				SaveFileDialog saveFileDialog = new SaveFileDialog();
				saveFileDialog.Filter = "Html Document(*.html)|*.html";
				saveFileDialog.FileName = "RunLog.html";
				if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
				{
					StreamWriter streamWriter = new StreamWriter(saveFileDialog.FileName);
					string text = "<table class=\"tablelistnowrap\" cellspacing=\"0\" cellpadding=\"0\">";
					text += "<tr>";
					text += "<th width=\"20%\">类型</th>";
					text += "<th width=\"80%\">消息</th>";
					text += "</tr>";
					foreach (GClass30 current in list)
					{
						text += "<tr>";
						text = text + "<td>" + current.LogCategoryName + "</td>";
						text = text + "<td>" + current.LogMessage + "</td>";
						text += "</tr>";
					}
					text += "</table>";
					streamWriter.Write(GClass0.smethod_11("运行出错记录", text));
					streamWriter.Close();
				}
			}
		}

		private void btnClear_Click(object sender, EventArgs e)
		{
			List<GClass30> list = GClass28.smethod_3();
			list.Clear();
			this.DataLog_Load(sender, e);
		}

		//protected override void vmethod_0(bool bool_0)
		//{
		//	if (bool_0 && this.components != null)
		//	{
		//		this.components.Dispose();
		//	}
		//	base.Dispose(bool_0);
		//}

		private void InitializeComponent()
		{
			this.gv_list = new DataGridView();
			this.CategoryName = new DataGridViewTextBoxColumn();
			this.LogMessage = new DataGridViewTextBoxColumn();
			this.bt_export = new Button();
			this.btnClear = new Button();
			this.lb_msg = new Label();
			((System.ComponentModel.ISupportInitialize)this.gv_list).BeginInit();
			base.SuspendLayout();
			this.gv_list.AllowUserToAddRows = false;
			this.gv_list.AllowUserToDeleteRows = false;
			this.gv_list.BackgroundColor = System.Drawing.Color.White;
			this.gv_list.Columns.AddRange(new DataGridViewColumn[]
			{
				this.CategoryName,
				this.LogMessage
			});
			this.gv_list.Location = new System.Drawing.Point(12, 12);
			this.gv_list.MultiSelect = false;
			this.gv_list.Name = "gv_list";
			this.gv_list.ReadOnly = true;
			this.gv_list.RowHeadersVisible = false;
			this.gv_list.RowTemplate.Height = 23;
			this.gv_list.SelectionMode = DataGridViewSelectionMode.CellSelect;
			this.gv_list.Size = new System.Drawing.Size(460, 250);
			this.gv_list.TabIndex = 0;
			this.CategoryName.DataPropertyName = "LogCategoryName";
			this.CategoryName.HeaderText = "类型";
			this.CategoryName.Name = "CategoryName";
			this.CategoryName.ReadOnly = true;
			this.CategoryName.Width = 160;
			this.LogMessage.DataPropertyName = "LogMessage";
			this.LogMessage.HeaderText = "消息";
			this.LogMessage.Name = "LogMessage";
			this.LogMessage.ReadOnly = true;
			this.LogMessage.Width = 270;
			this.bt_export.Location = new System.Drawing.Point(376, 277);
			this.bt_export.Name = "bt_export";
			this.bt_export.Size = new System.Drawing.Size(75, 23);
			this.bt_export.TabIndex = 1;
			this.bt_export.Text = "导出记录";
			this.bt_export.UseVisualStyleBackColor = true;
			this.bt_export.Click += new EventHandler(this.bt_export_Click);
			this.btnClear.Location = new System.Drawing.Point(295, 276);
			this.btnClear.Name = "btnClear";
			this.btnClear.Size = new System.Drawing.Size(75, 23);
			this.btnClear.TabIndex = 3;
			this.btnClear.Text = "清空记录";
			this.btnClear.UseVisualStyleBackColor = true;
			this.btnClear.Click += new EventHandler(this.btnClear_Click);
			this.lb_msg.AutoSize = true;
			this.lb_msg.Location = new System.Drawing.Point(12, 279);
			this.lb_msg.Name = "lb_msg";
			this.lb_msg.Size = new System.Drawing.Size(69, 19);
			this.lb_msg.TabIndex = 4;
			this.lb_msg.Text = "共“0”项";
			base.AutoScaleDimensions = new System.Drawing.SizeF(7f, 17f);
			base.AutoScaleMode = AutoScaleMode.Font;
			base.Controls.Add(this.lb_msg);
			base.Controls.Add(this.btnClear);
			base.Controls.Add(this.bt_export);
			base.Controls.Add(this.gv_list);
			this.Font = new System.Drawing.Font("微软雅黑", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, 134);
			base.Margin = new Padding(3, 4, 3, 4);
			base.Name = "DataLog";
			base.Size = new System.Drawing.Size(484, 312);
			base.Load += new EventHandler(this.DataLog_Load);
			((System.ComponentModel.ISupportInitialize)this.gv_list).EndInit();
			base.ResumeLayout(false);
			base.PerformLayout();
		}
	}
}
